home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / hugearr.zip / HUGELOAD.C < prev    next >
C/C++ Source or Header  |  1992-04-02  |  1KB  |  54 lines

  1.  
  2. #define NOCOMM
  3. #include <windows.h>
  4.  
  5. #include "hugearr.h"
  6.  
  7. /* Load a huge array that was previously saved in an operating system file. */
  8. /* VBM: Declare Function VBHugeLoad& Lib "hugearr.dll" Alias "VBHugeLoad" (ByVal hArray%, ByVal RecLen%, ByVal Fn$) */
  9. long FAR PASCAL
  10. VBHugeLoad(int hArray, int InLen, LPSTR FileSpec)
  11.     {
  12.     int       BytesRead;  /* number of bytes read from the file */
  13.     int       hLoadFile;  /* handle to the save file */
  14.     HPBYTE    ToBegin;    /* pointer for first element */
  15.     HPBYTE    ToElem;     /* pointer to array element */
  16.     long      element;    /* element in the huge array */
  17.     PHUGEDESC pArray;     /* pointer to array descriptor */
  18.  
  19.     DecCheckHandle(hArray);
  20.  
  21.     pArray = (PHUGEDESC) LocalLock(hLocalMem) + hArray;
  22.  
  23.     CheckNotAllocYet(pArray);
  24.  
  25.     /* Open the file */
  26.     if((hLoadFile = _lopen(FileSpec, OF_READ)) < 0)
  27.         {
  28.         LocalUnlock(hLocalMem);
  29.         return HA_FILEOPENERROR;
  30.         }
  31.  
  32.     ToBegin = (HPBYTE) GlobalLock(pArray -> handle);
  33.  
  34.     for(element = 0L; element <= pArray -> ubound ; element++)
  35.         {
  36.         /* calculate pointer to element */
  37.         ToElem = ToBegin + HugeElementOffset(element, pArray->perseg, pArray->recsize);
  38.  
  39.         /* Read the record */
  40.         BytesRead = _lread(hLoadFile, ToElem, InLen);
  41.  
  42.         if (BytesRead < 0)
  43.             element = HA_FILEREADERROR;
  44.         if (BytesRead <= 0)
  45.             break;
  46.         }
  47.  
  48.     /* Wrap up and return */
  49.     GlobalUnlock(pArray -> handle);
  50.     LocalUnlock(hLocalMem);
  51.     _lclose(hLoadFile);
  52.     return element;
  53.     }
  54.